package com.zhongyewx.teachercert.framework.skin;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import java.util.List;

public class SkinItem {
    private View view;

    private List<SkinAttr> attrs;

    public View getView() {
        return view;
    }

    public void setAttrs(List<SkinAttr> attrs) {
        this.attrs = attrs;
    }

    public SkinItem(View view, List<SkinAttr> attrs) {
        this.view = view;
        this.attrs = attrs;
    }

    public void apply(Context context) {
        if (view == null || attrs == null)
            return;
        for (SkinAttr attr : attrs) {
            String attrName = attr.getAttrName();
            String attrType = attr.getAttrType();
            String resName = attr.getResName();
            int resId = attr.getResId();
            if (ZYSkinFactory.ATTR_NAME_BG.equals(attrName)) {
                if (ZYSkinFactory.ATTR_TYPE_COLOR.equals(attrType)) {
                    view.setBackgroundColor(context.getResources().getColor(resId));
                } else if ("drawable".equals(attrType)) {
//                    view.setBackground(SkinManager.getInstance().getDrawable(resName,resId));
                }
            } else if (ZYSkinFactory.ATTR_NAME_TEXT.equals(attrName)) {
                if (view instanceof TextView && ZYSkinFactory.ATTR_TYPE_COLOR.equals(attrType)) {
                    ((TextView) view).setTextColor(context.getResources().getColor(resId));
                } else if (view instanceof TextView && ZYSkinFactory.ATTR_TYPE_SIZE.equals(attrType)) {
                    ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources().getDimension(resId));
                }
            }
        }
    }
}
